<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="x-ua-compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="minimal-ui,width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="white">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" type="image/x-icon" th:href="@{/images/favicon.ico}"/>
    <link rel="stylesheet" th:href="@{/css/bootstrap.css}">
    <link rel="stylesheet" th:href="@{/css/index.css}">
    <script type="text/javascript" th:src="@{/js/jquery-1.11.0.min.js}"></script>
    <title>登录</title>
</head>

<body class="app">
<div class="container">
    <form class="form-horizontal" action="#">
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <h2 class="text-center">登录</h2>
            </div>
        </div>
        <div class="form-group">
            <label for="username" class="col-sm-2 control-label">用户名</label>
            <div class="col-sm-10">
                <input class="form-control" id="username" value="admin" placeholder="输入用户名">
            </div>
        </div>
        <div class="form-group">
            <label for="password" class="col-sm-2 control-label">密码</label>
            <div class="col-sm-10">
                <input type="password" class="form-control" id="password" value="admin123456" placeholder="密码">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button"  id="submit" class="btn btn-warning btn-lg btn-block">登录</button>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <a href="/account/signup" class="btn btn-default btn-lg btn-block">注册</a>
            </div>
        </div>
    </form>
</div>
<script type="application/javascript">
    $("#submit").click(function () {
        var data = {
            username: $("#username").val(),
            password: $("#password").val()
        };
        $.ajax({
            type: "POST",
            contentType: "application/json;charset=UTF-8",
            url: "/account/login",
            data: JSON.stringify(data),
            dataType: 'json',
            success: function(result) {
                if (result.code == 0) {
                    window.location.href = "/apps"
                }
                console.log(result);
            }
        });
    })
</script>
</body>

</html>